package startup;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

import bazy.Baza;

import dystrybucja.ManagerRezerwacji;
import transport.ManagerPolaczen;
import uzytkownik.ManagerLogowania;

/**
 * 
 * @author Jacek
 *	Ta klasa dokonuje inicjalizacji managerow np wczytanie z bazy/pliku rozkladu polaczen itp
 */
public class SystemDworca {
	public static ManagerPolaczen managerPolaczen;
	public static ManagerRezerwacji managerRezerwacji;
	public static ManagerLogowania managerLogowania;
	
	public static void main(String[] argv){
			createDatabase();
			createTables();
			insertValues();
	}
	
	private static void createDatabase(){
		File file = new File("src/startup/create_database");
		
		Scanner in;
		StringBuilder st = new  StringBuilder();
		try {
			in = new Scanner(file);
			Baza.executeCreate(in.nextLine());
			while(in.hasNext())
				st.append(in.nextLine());
			Baza.executeCreate(st.toString());	
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		
		System.out.println("Utworzona baze danych!");
	}
	
	private static void createTables(){
		File path = new File("src/startup/create/");
		Scanner in;
		StringBuilder st = new  StringBuilder();
		for(File f : path.listFiles())
			try {
				in = new Scanner(f);
				while(in.hasNext())
					st.append(in.nextLine());
				Baza.executeCreate(st.toString());
				st = new StringBuilder();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		System.out.println("Utworzona tabele!");
	}
	
	private static void insertValues(){
		File path = new File("src/startup/insert/");
		Scanner in;
		StringBuilder st = new  StringBuilder();
		for(File f : path.listFiles())
			try {
				in = new Scanner(f);
				while(in.hasNext())
					st.append(in.nextLine());
				Baza.executeCreate(st.toString());
				st = new StringBuilder();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		System.out.println("Utworzona tabele!");
	}
}

